/*
Xern Entity Relocation Network
Copyright (C) 2011 Ronie Salgado <roniesalg@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef XTOOL_RAYTRACER_HPP
#define XTOOL_RAYTRACER_HPP

#include "MapData.hpp"
#include "Gpu.hpp"

namespace XernRay
{
    using namespace XernMap;

    class RayTracer
    {
    public:
        RayTracer();
        ~RayTracer();

        void InitScene(boost::shared_ptr<Object> object);
        void DisplayScene();

    private:
        void ScreenQuad();
        void RenderScene();
        void CastPrimaryRays();
        void AccumShade();

        int width, height;
        bool valid;
        size_t brushCount, faceCount, lightCount;
        size_t jitterSize;

        boost::shared_ptr<Program> passthroughProgram;
        boost::shared_ptr<Program> primaryCastProgram;
        boost::shared_ptr<Program> shadeProgram;
        boost::shared_ptr<TargetBuffer> framebuffer;
        boost::shared_ptr<LinearBuffer> faceBuffer, brushBuffer, lightBuffer;
        boost::shared_ptr<LinearBuffer> jitterBuffer;
        boost::shared_ptr<PingPongBuffer> colorBuffer;
        boost::shared_ptr<PingPongBuffer> rayBuffer;
        boost::shared_ptr<PingPongBuffer> normalBuffer;
        boost::shared_ptr<TextureBuffer> primaryRays;
        
        ReversibleTransform cameraTransform;        
    };
};

#endif //XTOOL_RAYTRACER_HPP

